<template>
  <div class="infinite-container">
      <!-- <div class="lefttime">
        状态：{{pageData.consultStatus | filterMedicalStatus}}
        <span v-if="pageData.leftTimeTxt!=='已超时'">
          (剩余时间{{pageData.leftTimeTxt}})
        </span>
        <span v-else>
          (已超时)
        </span>
      </div> -->
    <div class="bgwhite">
      <mu-list>
        <mu-list-item title="总费用">
          <span slot="right" class="feeText">￥{{money.amount}}</span>
        </mu-list-item>
        <mu-divider/>
        <mu-list-item title="自费金额">
          <span slot="right" class="feeText">￥{{money.amount}}</span>
        </mu-list-item>
      </mu-list>
    </div>
    <div class="mt10"></div>
    <pay-method @typeChange="typeChange"></pay-method>
    <div class="longBtnC">
      <mu-raised-button label="立即支付" fullWidth primary @click="pay" :disabled="isCanPay"></mu-raised-button>
    </div>
  </div>
</template>

<script>
import payMethod from "../../components/payMethod.vue";
import TimeCounter from "../../components/TimeCounter.js";
import { commonAjaxJson, RESTFUL_API } from "@/api/api";
import wxPay from "../../api/wxPay.js";
export default {
  data() {
    return {
      pageData: {},
      familyPerson: JSON.parse(sessionStorage.familyPerson || "{}"),
      agtOrderNumber: "",
      timeCounter: null,
      param: {},
      money: {},
      query: {},
      payType: 1
    }
  },
  computed: {
    isCanPay() {
      return this.pageData.leftTimeTxt === "已超时"
    }
  },
  components: {
    payMethod
  },
  mounted() {
    /**
     * query: {
     *  patientCode
     *  id
     * }
     */
    let data = this.$store.state.pageData
    this.pageData = data
    this.query = this.$route.query
    console.log(JSON.stringify(this.query))
    this.getPendingPaymentCalc()
  },
  methods: {
    typeChange (num) {
      this.payType = num
    },
    pay() {
      let body = {
        busType: 8,
        patientCode: this.query.patientCode,
        paymentOrderId: this.query.id || "",
        identificationNumbers: this.getAllRecipedId(),
        invoiceNumber: this.money.invoiceNumber || ""
      }
      let param = {
        userId: this.familyPerson.uid,
        mobile: JSON.parse(sessionStorage.getItem('medicalToBuyInfo')).list[0].mobile,
        total_amt: this.money.amount,
        order_subject: "在线支付",
        order_detail: "药品费用",
        username: JSON.parse(sessionStorage.getItem('medicalToBuyInfo')).list[0].patientName,
        body: JSON.stringify(body),
        payType: this.payType
      }
      console.log(JSON.stringify(param))
      window.location.href = 'app://drugPay?param=' + JSON.stringify(param)
    },
    payOk() {
      let param = {
        outTradeNo: this.agtOrderNumber
      }
      commonAjax("ppTrade/payProcessTrade", param, true).then(res => {
        if (res.data.code == 200) {
          console.log("his收到")
        }
      })
      this.$router.replace({
        path: "/payResult",
        query: {
          result: "ok",
          backPath: "/orderHistory/index",
          backName: "查看我的购药记录"
        }
      })
    },
    payFail() {
      this.$router.replace({
        path: "/payResult",
        query: {
          result: "fail",
          backPath: `/orderHistory/index`,
          backName: "返回"
        }
      })
    },
    getAllRecipedId() {
      if (this.pageData.identificationNumber) {
        return this.pageData.identificationNumber
      }
      let temp = []
      this.pageData.list.forEach(v => {
        temp.push('1-' + v.recipeId)
      })
      // return this.query.patientCode + '*' + temp.join(',')
      return temp
    },
    // 处方费用预结算
    getPendingPaymentCalc() {
      let query = this.$route.query
      commonAjaxJson(RESTFUL_API.buyDrugBudget, {
        consultId: query.consultId,
        takeWay: query.takeWay,
        province: query.province,
        city: query.province,
        county: query.county,
        township: query.township,
        detailedAddress: query.detailedAddress,
        consigneeName: query.consigneeName,
        consigneePhone: query.consigneePhone,
        boilSign: query.boilSign,
        expressCompanyCode: query.expressCompanyCode,
        expressFee: query.expressFee,
        freightCollect: query.freightCollect
        }, true)
        .then(res => {
          if (res.data.code == 200) {
            this.money = res.data.data
          } else {
            this.$store.commit('UPDATE_TOAST', {message: res.data.message || '服务错误', timeout: 3000})
          }
        })
    }
  }
}
</script>

<style scoped lang="less">
@import "../../common/css/vars";
@import "../../common/css/component";
.infinite-container {
  @{deep} .mu-item-left img {
    width: 30px;
    height: 30px;
  }
  @{deep} .mu-item.show-left {
    padding-left: 60px;
  }
  @{deep} .mu-item-title {
    color: #333;
  }
  @{deep} .mu-item-text {
    color: #ccc;
  }
  @{deep} .mu-item {
    min-height: 60px;
  }
  .lefttime {
    width: 100%;
    height: 30px;
    line-height: 30px;
    text-align: center;
    font-size: 14px;
    color: #ff6600;
    background: #fffdce;
  }
}
</style>
